package com.dongdongshop.controller;

import com.dongdongshop.data.Result;
import com.dongdongshop.pojo.TbUser;
import com.dongdongshop.service.TbItemService;
import com.dongdongshop.service.TbOrderService;
import com.dongdongshop.service.TborderitemService;
import com.dongdongshop.vo.CartVo;
import com.dongdongshop.vo.OrderVo;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("send")
public class OrderSendController {
    @DubboReference(check = false)
    private TborderitemService tborderitemService;

    @DubboReference(check = false)
    private TbOrderService orderService;

    @RequestMapping("getSend")
    @ResponseBody
    public Result getSend(){
        Subject subject = SecurityUtils.getSubject();
        TbUser user = (TbUser) subject.getPrincipal();
        try {
            List<OrderVo> orderVos = orderService.getSendListByUsername(user.getUsername());
            return Result.OK().setData(orderVos);
        }catch (Exception e){
            return Result.ERROR();
        }
    }
    @RequestMapping("tuiSend")
    public String tuiSend(String orderNum, String itemId,String tradeNum, Model m){
        m.addAttribute("WIDTRout_trade_no",orderNum);
        m.addAttribute("WIDTRout_request_no",itemId);
        m.addAttribute("WIDTRtrade_no",tradeNum);
        return "traderefund";

    }
}
